package com.adapter;

import com.BeyondCreative.bdolist.R;

import android.content.Context;
import android.database.DataSetObserver;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class ColorSelectAdapter implements SpinnerAdapter {
	Context mContext;
	int touchPosition;

	public ColorSelectAdapter(Context mContext) {
		super();
		this.mContext = mContext;
		this.touchPosition = -1;
	}
	
	public ColorSelectAdapter(Context mContext, int i) {
		super();
		this.mContext = mContext;
		this.touchPosition = i;
	}

	@Override
	public int getCount() {
		return 3;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	public void settouchPosition(int pos) {
		touchPosition = pos;

	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getItemViewType(int position) {

		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(touchPosition>-1){
			position = touchPosition;
		}
		ColorViewHolder holder = (ColorViewHolder) ViewHolder.getViewHolder(0);
		if (convertView == null) {
			convertView = new View(mContext);
			holder.tv = new TextView(mContext);
			convertView.setTag(holder);
		} else {
			holder = (ColorViewHolder) convertView.getTag();
		}
		if (position == 0) {
			holder.tv.setBackgroundResource(R.drawable.red_spinner);
		} else if (position == 1) {
			holder.tv.setBackgroundResource(R.drawable.green_spinner);
		} else {
			holder.tv.setBackgroundResource(R.drawable.blue_spinner);
		}
		return holder.tv;
	}

	@Override
	public int getViewTypeCount() {
		return 3;
	}

	@Override
	public boolean hasStableIds() {
		return false;
	}

	@Override
	public boolean isEmpty() {
		return false;
	}

	@Override
	public void registerDataSetObserver(DataSetObserver observer) {

	}

	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		TextView tv = new TextView(mContext);
		if (position == 0) {
			tv.setBackgroundResource(R.drawable.red_spinner);
			/*tv.setText(mContext.getResources().getString(R.string.first));
			tv.setTextSize(16 * mContext.getResources().getDisplayMetrics().density);*/
			return tv;
		} else if (position == 1) {

			tv.setBackgroundResource(R.drawable.green_spinner);
			/*tv.setText(mContext.getResources().getString(R.string.second));
			tv.setTextSize(16 * mContext.getResources().getDisplayMetrics().density);*/
			return tv;
		} else if (position == 2) {
			tv.setBackgroundResource(R.drawable.blue_spinner);
			/*tv.setText(mContext.getResources().getString(R.string.third));
			tv.setTextSize(16 * mContext.getResources().getDisplayMetrics().density);*/
			return tv;
		} else {
			return tv;
		}

	}

}
